package com.example.shop_2305.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.CategoryEntityItem
import com.example.shop_2305.R

class CateTwoAdapter:BaseQuickAdapter<CategoryEntityItem,BaseViewHolder>(R.layout.item_catetwo) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntityItem) {
        holder.setText(R.id.catetwo_tv,"-------${item.name}-------")
        //在适配器内部给rv赋值==类似在页面中赋值
        //找到rv
        val rv = holder.getView<RecyclerView>(R.id.catetwo_rv)
        //定义适配器并绑定
        val childAdapter = ChildAdapter()
        childAdapter.data.addAll(item.child)
        rv.adapter = childAdapter
        //设置显示样式
        rv.layoutManager = GridLayoutManager(context,3)
    }
}